package com.animation_study.mpandroidchart.fragment;

import com.animation_study.R;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

/**
 * Created by css on 2017/12/25.
 */

public class FanFragment extends BaseFragment {
    PieChart pieChart;
    ArrayList<String> lable;
    ArrayList<Entry> entries;

    @Override
    public int getLayout() {
        return R.layout.fragment_fan;
    }

    @Override
    protected void initView() {
        lable = new ArrayList<>();
        entries = new ArrayList<>();
        for (int i = 1; i <= 12; i++) {
            lable.add(i + "次");
            entries.add(new Entry(i, i));
        }

        pieChart = rootView.findViewById(R.id.pieChart);

        pieChart.setUsePercentValues(true);
        pieChart.setDescription("");
        pieChart.setExtraOffsets(5, 10, 5, 5);
//        pieChart.setDrawSliceText(false);//设置隐藏饼图上文字，只显示百分比  
        pieChart.setDrawHoleEnabled(true);
        pieChart.setHoleColorTransparent(true);


        pieChart.setTransparentCircleAlpha(110);

        pieChart.setHoleRadius(45f); //半径  
        //pieChart.setHoleRadius(0)  //实心圆  
        pieChart.setTransparentCircleRadius(48f);// 半透明圈  
        pieChart.setDrawCenterText(true);//饼状图中间可以添加文字  
        // 如果没有数据的时候，会显示这个，类似ListView的EmptyView  
        pieChart.setNoDataText("没有数据");
        pieChart.setUsePercentValues(true);//设置显示成比例  
        SimpleDateFormat format = new SimpleDateFormat("yyyy");

        pieChart.setRotationAngle(0); // 初始旋转角度  
        // enable rotation of the chart by touch  
        pieChart.setRotationEnabled(true); // 可以手动旋转  
        pieChart.setHighlightPerTapEnabled(true);
        pieChart.animateY(1000, Easing.EasingOption.EaseInOutQuad); //设置动画  
        Legend mLegend = pieChart.getLegend();  //设置比例图  
        mLegend.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT);  //左下边显示  
        mLegend.setFormSize(12f);//比例块字体大小  
        mLegend.setXEntrySpace(2f);//设置距离饼图的距离，防止与饼图重合  
        mLegend.setYEntrySpace(2f);
        //设置比例块换行...  
        mLegend.setWordWrapEnabled(true);
        mLegend.setDirection(Legend.LegendDirection.LEFT_TO_RIGHT);


        mLegend.setForm(Legend.LegendForm.SQUARE);//设置比例块形状，默认为方块  
//        mLegend.setEnabled(false);//设置禁用比例块  
        
        
        PieDataSet pieDataSet = new PieDataSet(entries, "饼图学习");
        PieData pieData = new PieData(lable, pieDataSet);
        pieChart.setData(pieData);
        ArrayList<Integer> colors = new ArrayList<Integer>();
        for (int c : ColorTemplate.JOYFUL_COLORS)
            colors.add(c);
//
        for (int c : ColorTemplate.COLORFUL_COLORS)
            colors.add(c);

        for (int c : ColorTemplate.LIBERTY_COLORS)
            colors.add(c);

//        for (int c : ColorTemplate.PASTEL_COLORS)
//            colors.add(c);

//        colors.add(getResources().getColor(R.color.stastic_team));
        pieDataSet.setColors(colors);


    }
}
